from boot import DatePicker, QFrame, QVBoxLayout, QWidget, Union, Qt, QDate


__all__ = ["QQ9DatePicker"]


class QQ9DatePicker(QFrame):

    def __init__(self, parent: Union[QWidget, None] = None):
        super().__init__(parent)

        self.setFixedSize(250, 35)

        # 主布局
        self.main_v_layout = QVBoxLayout()
        self.main_v_layout.setContentsMargins(0, 0, 0, 0)
        self.main_v_layout.setAlignment(Qt.AlignCenter)
        self.setLayout(self.main_v_layout)

        # 日期选择器
        self.date_picker = DatePicker()
        self.main_v_layout.addWidget(self.date_picker)

        # 设置样式
        self._set_style_sheet()

    def _set_style_sheet(self):
        self.setStyleSheet(
            """
            QQ9DatePicker {
                background-color: #F5F6F7;
                border: none;
                border-radius: 4px;
                font-size: 13px;
                font-family: "微软雅黑";
                color: #333333;
                padding-left: 5px;  /* 留出左侧图标的空间 */
                text-align: left;
            }
            QQ9DatePicker:focus {
                border: 1px solid #0099FF;;
            }
            """
        )

    def set_current_date(self):
        # 设置当前日期
        self.date_picker.setDate(QDate.currentDate())

    def set_date(self, date: str):
        # 设置日期，写入格式：yyyy/MM/dd
        self.date_picker.setDate(QDate.fromString(date, "yyyy/MM/dd"))

    def get_date(self):
        # 获取时间，返回格式：yyyy/MM/dd
        return self.date_picker.date.toString("yyyy/MM/dd")

